package com.gexiaobao.pigeon.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.TextView;

import com.gexiaobao.pigeon.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class MyMarkerView extends MarkerView {
    /**
     * Constructor. Sets up the MarkerView with a custom layout resource.
     *
     * @param context
     * @param layoutResource the layout resource to use for the MarkerView
     */
    private TextView textView;
    private TextView textViewDis;
    private DecimalFormat format;
    private List<String> mXData = new ArrayList<>();

    public MyMarkerView(Context context, List<String> xAxisData) {
        super(context, R.layout.linechart_marker_view);    //第二个参数为布局
        textView = findViewById(R.id.textview);
        textViewDis = findViewById(R.id.textviewDis);
        mXData = xAxisData;
        format = new DecimalFormat("##0.0000");
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        textView.setText("分速: " + format.format(e.getY()));
        textViewDis.setText("距离: " + mXData.get((int) e.getX()));
        super.refreshContent(e, highlight);
    }

    public MPPointF getOffset() {
        return new MPPointF(-((float) getWidth() / 2), -getHeight() - 20);
    }
}